package com.fable.timer;

import com.fable.base.PaginationResult;
import com.fable.biz.operate.CustomerService;
import com.fable.biz.operate.dto.CustomerDTO;
import com.fable.biz.operate.query.CustomerQueryCondition;
import com.fable.utils.CalendarUtil;
import com.fable.utils.SmsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by weishuai on 18/4/20.
 */
public class TimerTaskImpl implements TimerTask {

    private static final Logger log = LoggerFactory.getLogger(TimerTaskImpl.class);
    @Resource
    CustomerService customerService;

    @Override
    public void sendMessage() {
        /*log.info("发送到期客户短信通知给boss");
        CustomerQueryCondition condition = new CustomerQueryCondition();
        Date currTime = new Date();
        Date certificateTime = CalendarUtil.addDate(currTime, 120);
        String endTime = CalendarUtil.toString(certificateTime, CalendarUtil.DATE_FMT_3);
        //获取4个月后月份和日期
        String monthAndDate=endTime.substring(endTime.indexOf("-"));
        condition.setCertificateTime(monthAndDate);

        PaginationResult<CustomerDTO> result = customerService.searchCustomer(condition);
        List<CustomerDTO> list = result.getResultList();
        StringBuffer buffer = new StringBuffer();
        if (!CollectionUtils.isEmpty(list)) {
            for (int i = 0; i < list.size(); i++) {
                if (i >= 10) {
                    buffer.append("...更多到期客户请登录系统查询.");
                    continue;
                }
                CustomerDTO customerDTO = list.get(i);
                buffer.append(i + 1).append(".").append(customerDTO.getCompanyName()).append(";");

            }
            boolean sendResponse = SmsUtil.sendMessage("17712169979", buffer.toString());
            log.info("发送短信结果:response:{},content", sendResponse, buffer.toString());
        }*/
    }
}
